<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        // 为数组添加一个共享方法，将数组中的奇数个挑选出来存放到新数组中并返回
        Array.prototype.selectOdd=function(){
            var newArr=[];
            for(var i=0;i<this.length;i++){
                if(i%2==0){
                    newArr.push(this[i]);
                }
            }
            return newArr;
        };
        var arrs=["a","b","c","d","e","f"];
        console.log(arrs.selectOdd());
        var arrays=["alice","baby","cici","lili","bebe"];
        console.log(arrays.selectOdd());

        // 为数组添加一个共享方法，交换数组中两个元素的位置，并返回这个数组
        Array.prototype.switchLoc=function(index1,index2){
            var temp=this[index1];
            this[index1]=this[index2];
            this[index2]=temp;
            return this;
        };
        var arr=["熊","羊","狗","鸡","猪","鸭"];
        console.log(arr.switchLoc(0,arr.length-1));
        var arr2=["杨过","小龙女","尹志平","丘处机","王重阳"];
        console.log(arr2.switchLoc(2,arr2.length-1));
    </script>
</head>
<body>
    
</body>
</html>